<?php

/**
 * php 流程控制
 */


// if else
$a = true;
if ($a == true) {
    echo 'true';
} else {
    echo 'false';
}
echo PHP_EOL;

// switch
$b = 1;
switch ($b = 1) {
    case 1:
        echo '1';
        break;
    case 2:
        echo '2';
        break;
    default:
        echo '0';
        break;
}
echo PHP_EOL;

// while
$i = 10;
while ($i <= 15) {
    echo 'i is ' . $i . PHP_EOL;
    $i++;
}


// do while
$i = 1;
do {
    $i++;
    echo 'i is ' . $i . PHP_EOL;

} while ($i <= 5);
echo PHP_EOL;

// for foreach
for ($i = 1; $i < 3; $i++) {
    echo 'for i is ' . $i . PHP_EOL;
}
echo PHP_EOL;

$arr = [1, 2, 3, 7, 8];
foreach ($arr as $key => $value) {
    echo 'foreach key is ' . $key . ' value is ' . $value . PHP_EOL;
}
echo PHP_EOL;

$brr = [
    [1, 3],
    [2, 4]
];
foreach ($brr as list($key, $value)) {

    echo 'list key = ' . $key . ' value = ' . $value . PHP_EOL;
}

foreach ($brr as $key => $item) {
    echo 'key = ' . $key . PHP_EOL;
    print_r($item);
}